package com.example.wyc.mybiye1.sql;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;

import com.example.wyc.mybiye1.lei.guangMingLei;

/**
 * Created by sy on 18-10-26.
 */

public class MYSQL {

    Context context;
    MYDB mydb;
    SQLiteDatabase sqLiteDatabase;
    guangMingLei gmLei;
    public MYSQL(Context context){
        this.context=context;
        mydb=new MYDB(context,"myBieYeSql.db",null,1);
        sqLiteDatabase=mydb.getReadableDatabase();

    }

    public void baoCunGuangMin(String name,String time){
        ContentValues value=new ContentValues();
        value.put("name",name);
        value.put("time",time);
        sqLiteDatabase.insert("guangMing",null,value);
    }

    public void chaXunGuangMing(){
        StringBuilder sb=new StringBuilder();
        Cursor cursor=sqLiteDatabase.query("guangMing",null,null,null,null,null,null);

        if (cursor.moveToFirst()){
            do {
                String nn=cursor.getString(cursor.getColumnIndex("name"));
                String tt=cursor.getString(cursor.getColumnIndex("time"));
                sb.append("  wenDu："+nn+"  时间："+tt+"\n");
            }while (cursor.moveToNext());
        }

        cursor.close();
        Toast.makeText(context,sb.toString(),Toast.LENGTH_LONG).show();
    }

    public guangMingLei chaXunGuangMing2(){
        gmLei=new guangMingLei();
        StringBuilder sb=new StringBuilder();
        Cursor cursor=sqLiteDatabase.query("guangMing",null,null,null,null,null,null);

        if (cursor.moveToFirst()){
            do {
                String nn=cursor.getString(cursor.getColumnIndex("name"));
                String tt=cursor.getString(cursor.getColumnIndex("time"));
                sb.append("  wenDu："+nn+"  时间："+tt+"\n");
                gmLei.Gms.add(nn);
                gmLei.times.add(tt);
            }while (cursor.moveToNext());
        }

        cursor.close();
        Toast.makeText(context,sb.toString(),Toast.LENGTH_LONG).show();
        return gmLei;
    }

    public void shanChu(){
        sqLiteDatabase.delete("guangMing",null,null);
    }
}
